﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.CodingListVMs
{
    public partial class CodingListListVM : BasePagedListVM<CodingList_View, CodingListSearcher>
    {
        
        protected override IEnumerable<IGridColumn<CodingList_View>> InitGridHeader()
        {
            return new List<GridColumn<CodingList_View>>{
                
                this.MakeGridHeader(x => x.CodingList_Code).SetTitle(@Localizer["Page.编码"].Value),
                this.MakeGridHeader(x => x.CodingList_CurrentNumber).SetTitle(@Localizer["Page.当前流水号"].Value),
                this.MakeGridHeader(x => x.CodingList_Example).SetTitle(@Localizer["Page.当前编码"].Value),
                this.MakeGridHeader(x => x.CodingList_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.CodingList_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.CodingList_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.CodingList_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.CodingList_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<CodingList_View> GetSearchQuery()
        {
            var query = DC.Set<CodingList>()
                
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckEqual(Searcher.CurrentNumber, x=>x.CurrentNumber)
                .CheckContain(Searcher.Example, x=>x.Example)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new CodingList_View
                {
				    ID = x.ID,
                    
                    CodingList_Code = x.Code,
                    CodingList_CurrentNumber = x.CurrentNumber,
                    CodingList_Example = x.Example,
                    CodingList_CreateTime = x.CreateTime,
                    CodingList_UpdateTime = x.UpdateTime,
                    CodingList_CreateBy = x.CreateBy,
                    CodingList_UpdateBy = x.UpdateBy,
                    CodingList_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class CodingList_View: CodingList
    {
        
        public string CodingList_Code { get; set; }
        public int? CodingList_CurrentNumber { get; set; }
        public string CodingList_Example { get; set; }
        public DateTime? CodingList_CreateTime { get; set; }
        public DateTime? CodingList_UpdateTime { get; set; }
        public string CodingList_CreateBy { get; set; }
        public string CodingList_UpdateBy { get; set; }
        public bool CodingList_IsValid { get; set; }

    }

}